import SwiftUI
import SystemConfiguration.CaptiveNetwork
import UIKit
import Foundation
 
struct WifiInfoView: View {
    @StateObject private var viewModel = WifiInfoViewModel()
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {
        NavigationView {
            ZStack {
                MainView()
                VStack {
                    Back(title: "WiFi Security", onBackTap: {
                        self.presentationMode.wrappedValue.dismiss()
                    }, onImageTap: {})
                    Image("mainimg").resizable(resizingMode: .stretch).aspectRatio(contentMode: .fill)
                        .frame(width: 230,height: 230)
                    Text("Network security status:")
                        .foregroundColor(.white)
                    Text("Safe")
                        .foregroundColor(Color("alphaStart")).padding(.top,2)
                    
                    Image("ll")
                    
                    VStack(alignment: .leading, spacing: 20) {
                        HStack {
                            Text("Wi-Fi name:")
                                .foregroundColor(.white)
                            Spacer()
                            Text(viewModel.ssid)
                                .foregroundColor(.white)
                        }
                        HStack {
                            Text("Local IP Address:")
                                .foregroundColor(.white)
                            Spacer()
                            Text(viewModel.localIPAddress)
                                .foregroundColor(.white)
                        }
                        HStack {
                            Text("External IP Address:")
                                .foregroundColor(.white)
                            Spacer()
                            Text(viewModel.externalIPAddress)
                                .foregroundColor(.white)
                        }
                        HStack {
                            Text("Network Type:")
                                .foregroundColor(.white)
                            Spacer()
                            Text(viewModel.networkStatus)
                                .foregroundColor(.white)
                        }
                    }
                    .padding()
                    .padding(.horizontal,10)

                    
                    Button(action: {
                        showToast(message: "Data refresh successful.", duration: 2.0)
                    }, label: {
                        VStack {
                            HStack {
                                Spacer()
                                Text("Test Again")
                                    .font(.title3)
                                    .foregroundColor(.black)
                                    .padding(.all,10)
                                Spacer()
                            }
                            .background(Color("alphaStart"))
                            .cornerRadius(10)
                            .padding()
                        }.padding(.horizontal)
                    })

                    
                    Spacer()
                   
                }
            }  .navigationBarHidden(true)
                .navigationBarBackButtonHidden(true)
                .navigationViewStyle(StackNavigationViewStyle())
            .navigationBarHidden(true)
        }  .navigationBarHidden(true)
            .navigationBarBackButtonHidden(true)
            .navigationViewStyle(StackNavigationViewStyle())
    }
}



#Preview {
    WifiInfoView()
}
